<template>
  <!--  <h2>接收审批记录</h2>-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流程名称" prop="instanceName">
        <el-input v-model="queryParams.instanceName" placeholder="请输入流程名称" clearable style="width: 240px"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8" ref="refbut">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="dataList" :height="tableHeight" border >
      <!--      <el-table-column label="流程ID" align="center" prop="id"/>-->
      <el-table-column label="流程名称" align="center" prop="instanceName" />
      <el-table-column label="任务节点名称" align="center" prop="name" />
      <el-table-column label="办理人" align="center" prop="assignee" />
      <el-table-column label="创建时间" align="center" prop="startTime" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="examineAndApprove(scope.row)">审批</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 档案移交审批单 -->
    <!-- isType:1 代表从待办任务打开的 -->
    <archiveHandOver v-if="archiveHandOverRow" :open="archiveHandOverOpen" @closeDelDialog="closeDelDialog"
      ref="archiveHandOverRef" :printRow="archiveHandOverRow" :isType="2" source="receivingApprovalRecords"
      :printTitle='printTitle' :printShow="false" @submitprint="submitprint"></archiveHandOver>

  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import estimateTableHeight from "@/mixins/estimateTableHeight";
import printOrder from "@/views/archive/archiveTransfer/offline/printOrder";
import { listTask } from "@/api/archive/digitalizeReceive/electronicArchives/receivingApprovalRecords";
import { getDicts_archive } from "@/api/archive/dict/dictManageData";
import archiveHandOver from "@/views/archive/archiveTransfer/offline/printOrder.vue";
import { formDataSave } from "@/api/archive/archiveTransfer/task";

export default {
  name: "index",
  components: { Treeselect, printOrder, archiveHandOver },
  mixins: [estimateTableHeight], // 混入方法
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        instanceName: undefined
      },
      loading: true,
      dataList: [],
      total: 0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 选择是否办结
      completionOption: [
        { value: '0', label: '否' },
        { value: '1', label: '是' }
      ],
      archiveHandOverRow: "",
      archiveHandOverOpen: false,
      otherForm: {
        resource: undefined,
        note: undefined
      },
      printTitle: "",
      // 显示搜索条件
      showSearch: true,
    }
  },
  created() {
    this.getOption()
    this.getList()
  },
  methods: {
    // 获取流程定义字典
    getOption() {
      getDicts_archive('WORK_FLOW_KEY').then(response => {
        this.flowPathOption = response.data.map(item => {
          return {
            value: item.dictValue,
            label: item.dictLabel
          }
        })
      })
    },
    table_index(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    getList() {
      listTask(this.queryParams).then(res => {
        this.loading = false
        this.total = res.total
        this.dataList = res.rows
      })
    },
    examineAndApprove(row) {
      console.log(row, "-----------------")
      this.id = row.id
      // this.reset();
      this.$nextTick(() => {
        this.archiveHandOverRow = row.processVariables
        // this.$refs.archiveHandOverRef.init(row);
        this.archiveHandOverOpen = true
      })
      this.getList();
    },
    submitChild(childForm) {
      this.otherForm = childForm;
      this.submit();
    },
    // 提交
    submit() {
      var data = []
      if (this.otherForm.resource == '1') {
        data = [{
          controlId: 'is_agree',
          controlDefault: '不同意--__--同意',
          controlIsParam: 'i',
          controlLable: '审批意见',
          controlType: 'radio',
          controlValue: 1
        }, {
          controlId: "comment",
          controlDefault: 'FormProperty_2ugo1se',
          controlIsParam: 'f--!!null',
          controlLable: '批注',
          controlType: 'textarea',
          controlValue: this.otherForm.note
        }];
        data.id = this.id
        formDataSave(this.id, data).then(response => {
          this.getOption()
          this.getList();
          this.$modal.msgSuccess(response.msg)
        })
      } else {
        data = [{
          controlId: 'is_agree',
          controlDefault: '不同意--__--同意',
          controlIsParam: 'i',
          controlLable: '审批意见',
          controlType: 'radio',
          controlValue: 0
        }, {
          controlId: "comment",
          controlDefault: 'FormProperty_2ugo1se',
          controlIsParam: 'f--!!null',
          controlLable: '批注',
          controlType: 'textarea',
          controlValue: this.otherForm.note
        }];
        data.id = this.id
        formDataSave(this.id, data).then(response => {
          if (response.code == "200") {
            this.getOption()
            this.getList();
            this.$modal.msgSuccess(response.msg)
          } else {
          }
        })
      }

    },
    //关闭弹窗
    closeDelDialog() {
      this.archiveHandOverOpen = false;
      this.getList()
    },
    submitprint(){
      this.archiveHandOverOpen = false;
      this.getList()
    },
  }
}
</script>

<style scoped></style>
